<template>
  <div>
    <div style="background: #fff; padding: 20px;height: 90vh;margin-top: 80px;overflow: hidden;overflow-y: scroll;">
      <h4>个人玩乐点推荐</h4>
      <h5>根据您的喜好向您自动推荐  <span class="route cp" @click="toAll">查看全部玩乐点</span></h5>
     <div
          class="each-fun flex-between cp"
          v-for="(item, index) in funList"
          @click="toDetail(item)"
          :key="index"
        >
          <div class="l">
            <div class="flex-between">
              <div class="flex-center">
                <!-- <div class="no">{{ index + 1 }}</div> -->
                <div class="name">{{ item.funName }}</div>
              </div>
              <div class="comments">{{ item.comments.length }}条评论</div>
            </div>
            <div class="desc">
              {{ item.funDesc }}
            </div>
          </div>

          <div class="r flex-between">
            <img class="img1" :src="item.pics[0]" alt="" />
            <div style="width: 50%;">
              <img v-if="item.pics.length>1" class="img2" :src="item.pics[1]" alt="" />
              <img v-if="item.pics.length>2" class="img3" :src="item.pics[2]" alt="" />
            </div>
          </div>
        </div>

    </div>
  </div>
</template>

<script>
import {
  getFun,
  getUserInfo
} from '../service'
export default {
  data() {
    return {
      userInfo: {},
      funList: []
    };
  },
  created() {
    let ls = localStorage.getItem('meiyaWebInfo')
    if (ls) {
      this.userInfo = JSON.parse(ls);
      getUserInfo(this.userInfo._id).then((res) => {
        this.userInfo = {
          ...res.data,
          stars: JSON.parse(res.data.stars),
          tickets: res.data.tickets ? JSON.parse(res.data.tickets) : [],
        };
        this.getFun()
      });
    } else {
      this.$notify({
        title: '提示',
        message: '请先登录',
        duration: 0
      });
    }
  },
  methods: {
    getFun() {
      this.funList = []
      getFun().then(res => {
        for (let item of res.data) {
          item.pics = item.pics.split(",");
          item.comments = JSON.parse(item.comments);
          item.likes = JSON.parse(item.likes);
          item.tickets = JSON.parse(item.tickets);
          let likes = this.userInfo.likes.split(',')
          let types = item.types.split(',')
          let jj = likes.filter(v => {
            return types.includes(v)
          })
          if (jj.length) {
            this.funList.push(item)
          }
        }
      })
    },
    toDetail(params) {
      this.$router.push({
        name: "Detail",
        params: {
          id: params._id,
        },
      });
      localStorage.setItem(
        "meiyaFunDetail",
        JSON.stringify({
          id: params._id,
        })
      );
    },
    toAll() {
      this.$router.push('list')
    }
  }
};
</script>

<style lang="scss" scoped>
h4 {
  text-align: center;
  font-weight: bold;
}

.name {
  font-size: 20px;
  font-weight: bold;
  line-height: 40px;
}
.desc {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  /* autoprefixer: off */
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 7;
  word-break: break-all;
  line-height: 24px;
}

.each-fun {
  padding: 20px;
  margin-top: 10px;
  display: flex;

  .l {
    width: 48%;
    .no {
      float: left;
      margin-right: 18px;
      width: 20px;
      height: 20px;
      border-radius: 2px;
      background-color: #ff9d00;
      text-align: center;
      color: #fff;
      font-size: 14px;
    }
    .name {
      color: #ff9d00;
      font-size: 18px;
      line-height: 20px;
      font-weight: normal;
    }
    .comments {
      font-size: 12px;
      color: #ff9d00;
    }

    .desc {
      font-size: 16px;
      margin-top: 20px;
    }
  }

  .r {
    width: 48%;
    .img1 {
      width: 50%;
      height: 200px;
      margin-right: 10px;
    }
    .img2 {
      width: 100%;
      margin-bottom: 10px;
      height: 95px;
    }

    .img3 {
      width: 100%;
      height: 95px;
    }
  }
}

.flex-between {
  display: flex;
  justify-content: space-between;
}
.flex-center {
  display: flex;
  align-items: center;
}

.imgs {
  width: 100%;
  display: flex;
  flex-wrap: wrap;

  .each:hover {
    img {
      transform: scale(1.1)
    }
  }

  & > div {
    width: 20%;
    padding: 12px;

    img {
      width: 100%;
      height: 150px;
      cursor: pointer;
      transition: all 0.3s
    }

    .name-bottom {
      margin-top: 10px;
      width: 100%;
      text-align: center;
      height: 43px;
      line-height: 42px;
      padding: 0 10px;
    }
  }
  & > div:hover {
    color: #ff9d00;
  }
}

.cp {
  cursor: pointer;
}
.route {
    color: #ff9d00;
}
h5 {
  text-align: right;
}
</style>